﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Legend.Fakes.ExtensionSyntax;
using Legend.Fakes.Api;
using Legend.Fakes.Configuration;

namespace Legend.Fakes.Tests.Api
{
    [TestFixture]
    public class FakeObjectTests
    {
        [Test, Ignore]
        public void Calls_configured_in_a_child_context_does_not_exist_outside_that_context()
        {
            var fake = new FakeObject(typeof(IFoo));
            var config = new FakeConfiguration<IFoo>(fake);

            using (Fake.CreateScope())
            {
                config.CallsTo(x => x.Baz()).Returns(10);
            }

            Assert.That(((IFoo)fake.Object).Baz(), Is.Not.EqualTo(10));
        }

        [Test]
        public void Event_listeners_that_are_removed_should_not_be_invoked_when_event_is_raised()
        {
            var foo = A.Fake<IFoo>();
            var called = false;
            EventHandler listener = (s, e) => called = true;

            foo.SomethingHappened += listener;
            foo.SomethingHappened -= listener;

            foo.SomethingHappened += Raise.With(EventArgs.Empty).Now;
            
            Assert.That(called, Is.False);
        }
    }
}
